package com.ltt.dao.vo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * @author ‘李天泰’
 * @version 1.0
 * @description: TODO
 * @date 2023/4/30 15:27
 */
@Data
@AllArgsConstructor
@ApiModel("统一返回结果")
public class Result<T> {
    private static final String SUCCESS = "success";
    private static final String FAILED = "failed";

    // 封装当前请求处理的结果是成功还是失败
    @ApiModelProperty("返回的状态码")
    private String result;

    // 请求处理失败时返回的信息
    @ApiModelProperty("错误信息")
    private String message;

    // 要返回的数据
    @ApiModelProperty("返回的数据")
    private T data;

    /**
     * @param
     * @return com.ltt.dao.vo.Result<Type>
     * @description: 成功且不需要返回数据
     */
    public static <Type> Result<Type> successWithoutData() {
        return new Result<>(SUCCESS, null, null);
    }

    /**
     * @param data
     * @return com.ltt.dao.vo.Result<Type>
     * @description: 成功且返回对于值
     */
    public static <Type> Result<Type> successWithData(Type data) {
        return new Result<>(SUCCESS, null, data);
    }

    public static <Type> Result<Type> failed(String message) {
        return new Result<>(FAILED, message, null);
    }

}
